package com.towker;

import com.jacob.com.Variant;
import org.nethawker.word11.*;

public class testWord {
    private static Application objWord;
    private static Documents documents;
    private static Document document;
    private static Selection selection;
    public static void main(String[] args) {
        try {
            objWord = new Application();
            //objWord.setScreenUpdating(false);
            objWord.setVisible(true);
            documents = objWord.getDocuments();
            document = documents.add();

            Range range = document.getParagraphs().add().getRange();
            range.insertBefore("1");
            range.setBold(1);
            range.getParagraphFormat().setAlignment(1);
            range.getFont().setName("Arial");
            range.getFont().setSize(12);
            range.getFont().setColorIndex(3);

            document.getParagraphs().add().getRange().insertBefore("");

            int column = 2;
            int row = 5;
            Range range2 = document.getParagraphs().add().getRange();
            Table table1 = document.getTables().add(range2, row, column);
           
            for (int i = 1; i <= column; i++) {
                table1.cell(1, i).getRange().insertAfter("one" + i);
                table1.cell(1,
                        i).getRange().getParagraphFormat().setAlignment(1);
            }

            for (int i = 1; i <= column; i++) {
                for (int j = 2; j <= row; j++) {
                    table1.cell(j, i).getRange().insertAfter("ֵ" + j + "," + i);
                    table1.cell(j, i).getRange().getParagraphFormat().
                            setAlignment(1);
                }
            }
            Thread.sleep(5000);
            document.saveAs(new Variant("C:\\TestDoc.doc"));
            objWord.quit();
            /*objWord = new Application();
                     objWord.setVisible(true);


                     documents = objWord.getDocuments();
             document = documents.open(new Variant("F:\\ss.doc"), new Variant(false),
                                      new Variant(false));
                     Range range = document.getContent();
                     //java.lang.System.out.println(range.getRows().add(new Variant("sdfsdf")));
                     range.insertAfter("dfsdf");
                     Find find = range.getFind();

                     Variant f = new Variant(false);
                     boolean rt = true;
                     while (rt) {
                rt = find.execute(new Variant("ss"), f, f, f, f, f, f, f, f,
                                  new Variant("TT"), new Variant(true));
                     }

                     document.saveAs(new Variant("C:\\ss1.doc"));
                     document.close();
                     objWord.quit();*/
        }catch (Exception e) {
            java.lang.System.out.println("message: " + e.getMessage());
        }
        finally{
            //objWord.setScreenUpdating(true);
        }


    }
}
